﻿ IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[AccionesGanadoras]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [dbo].[AccionesGanadoras]
GO
CREATE FUNCTION AccionesGanadoras
(  
	@promocionId AS INT,
	@participanteId AS INT    
)
RETURNS VARCHAR(100)    
BEGIN   
	DECLARE @result AS VARCHAR(100)
	SELECT @result = CONVERT(VARCHAR, COUNT(*))
	FROM Accion
	WHERE	promocionId = @promocionId
	AND		participanteId = @participanteId
	AND		Ganador = 1    
	RETURN @result
END
GO